﻿@{
    ViewBag.Title = "Details";
    Layout = "~/Areas/OrderFlowManage/Views/Shared/_DetailLayout.cshtml";
}

<div class="panel panel-default">
    <!-- Nav tabs -->
    <ul id="stateNavTabs" class="nav nav-tabs" role="tablist">
        <li role="presentation"><a href="#state0" aria-controls="state0" role="tab" data-toggle="tab" style="border-left-width: 0;">流转记录</a></li>
        <li role="presentation"><a href="#state1" aria-controls="state1" role="tab" data-toggle="tab">推荐场地</a></li>
        <li role="presentation"><a href="#state2" aria-controls="state2" role="tab" data-toggle="tab">带看场地</a></li>
        <li role="presentation"><a href="#state3" aria-controls="state3" role="tab" data-toggle="tab">意向场地报价</a></li>
        <li role="presentation"><a href="#state4" aria-controls="state4" role="tab" data-toggle="tab">价格审核</a></li>
        <li role="presentation"><a href="#state5" aria-controls="state5" role="tab" data-toggle="tab">场地预定</a></li>
        <li role="presentation"><a href="#state6" aria-controls="state6" role="tab" data-toggle="tab">用印申请</a></li>
        <li role="presentation"><a href="#state7" aria-controls="state7" role="tab" data-toggle="tab">签订合同</a></li>
    </ul>
    <!-- Tab panes -->
    <div class="tab-content" style="padding: 10px 10px 0px 10px;">
        @*流转记录*@
        <div role="tabpanel" class="tab-pane state-content" id="state0">

            <div class="panel panel-primary">
                <div class="panel-heading"><span class="h5">审批记录</span></div>
                <table class="table table-condensed table-hover">
                    <thead>
                        <tr>
                            <td>申请类型</td>
                            <td>申请时间</td>
                            @*<td>场地-空间</td>*@
                            <td>申请内容</td>
                            <td>审核人</td>
                            <td>审核结果</td>
                            <td>审核时间</td>
                            <td>备注</td>
                        </tr>
                    </thead>
                    <tbody id="gridOrderCheckRecordList"></tbody>
                </table>
            </div>

            <div class="panel panel-primary">
                <div class="panel-heading"><span class="h5">场地推荐记录</span></div>
                <table class="table table-condensed table-hover">
                    <thead>
                        <tr>
                            <td width="200">场地名称</td>
                            <td width="200">空间名称</td>
                            <td width="200">推荐时间</td>
                            <td>备注</td>
                        </tr>
                    </thead>
                    <tbody id="gridOrderRecommendList"></tbody>
                </table>
            </div>

            <div class="panel panel-primary">
                <div class="panel-heading"><span class="h5">场地带看记录</span></div>
                <table class="table table-condensed table-hover">
                    <thead>
                        <tr>
                            <td width="200">场地名称</td>
                            <td width="200">销售人员</td>
                            <td width="200">陪同人员</td>
                            <td width="200">场地跟进人员</td>
                            <td width="200">带看时间</td>
                            <td>备注</td>
                        </tr>
                    </thead>
                    <tbody id="gridOrderTakelookList"></tbody>
                </table>
            </div>
        </div>

        @*推荐场地*@
        <div role="tabpanel" class="tab-pane state-content" id="state1">
            <div class="panel panel-default">
                <table class="table table-border table-hover">
                    <thead>
                        <tr>
                            <td colspan="3">
                                <table class="form">
                                    <tr>
                                        <th class="formTitle">城市：</th>
                                        <td class="formValue">
                                            <select id="txt_cityid" name="txt_cityid" class="form-control" multiple></select>
                                        </td>
                                        <th class="formTitle">活动类型：</th>
                                        <td class="formValue">
                                            <select id="txt_acttype" name="txt_acttype" class="select2-container select2-container--default select2-container--open required"></select>

                                        </td>
                                        <th class="formTitle">场地大小(㎡)：</th>
                                        <td class="formValue">
                                            <input id="txt_area" name="txt_area" type="text" class="form-control" style="width:80%;" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <th class="formTitle">区域：</th>
                                        <td class="formValue">
                                            <select id="txt_districtid" name="txt_districtid" class="form-control" multiple></select>
                                        </td>

                                        <th class="formTitle">场地类型：</th>
                                        <td class="formValue">
                                            <select id="txt_sitetype" name="txt_sitetype" class="form-control" multiple></select>
                                        </td>
                                        <th class="formTitle">空间价格/天：</th>
                                        <td class="formValue">
                                            <div class="input-group">
                                                <input id="txt_minmoney" name="txt_minmoney" type="text" class="form-control" style="width:70px;">
                                                <span class="input-group-addon" style="border-right-width: 0; border-left-width: 0;">~</span>
                                                <input id="txt_maxmoney" name="txt_maxmoney" type="text" class="form-control" style="width:70px;">
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <th class="formTitle">商圈：</th>
                                        <td class="formValue">
                                            <select id="txt_business_area" name="txt_business_area" class="form-control" multiple></select>
                                        </td>
                                        <th class="formTitle">关键字搜索：</th>
                                        <td class="formValue">
                                            <input id="txt_keyword" name="txt_keyword" type="text" class="form-control" style="width:100%" />
                                        </td>
                                        <td colspan="2" align="left" style="padding-left:80px;"></td>
                                    </tr>
                                    <tr>
                                        <td colspan="6" align="right" style="padding-right:15px;">
                                            <div class="btn-group btn-group-sm" role="group">
                                                <a class="btn btn-info" onclick="vm.sendsite.bindSearch()"><span class="glyphicon glyphicon-refresh"></span></a>
                                                <button id="btn_site_reset" type="button" class="btn btn-danger">重置</button>
                                                <button id="btn_search" type="button" class="btn btn-primary">查询</button>
                                                <button id="btn_add_demand" type="button" class="btn btn-info">新增场地需求</button>
                                                <button id="btn_sitesave" type="button" class="btn btn-danger" disabled>咨询档期/价格</button>
                                                <a href="#" style="float:left;" class="dropdown-toggle" data-toggle="dropdown">
                                                    <b class="caret"></b>
                                                </a>
                                                <ul class="dropdown-menu" style="left: 250px;" id="menu"></ul>
                                                <button id="btn_flowtake" type="button" class="btn btn-primary">流程跳转</button>
                                            </div>
                                            <div class="btn-group btn-group-sm" role="group">
                                                <button id="btn_email" type="button" class="btn btn-primary">发送邮件和短信</button>
                                                @*<button id="btn_add_repoert" type="button" class="btn btn-danger">销售日报</button>*@
                                                <button id="btn_sitesave_flow" type="button" class="btn btn-danger" disabled>审核结果</button>
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td colspan="3">
                                <div class="gridPanel">
                                    <table id="gridList" style="width:100%;"></table>
                                    <div id="gridPager"></div>
                                </div>
                            </td>
                        </tr>
                    </tbody>
                </table>

            </div>
        </div>

        @*带看场地*@
        <div role="tabpanel" class="tab-pane state-content" id="state2">

            <div class="panel panel-default">
                <div class="panel-heading">
                    <div>
                        <div class="pull-left"><span class="h5"></span></div>
                        <div class="pull-right">
                            <div class="btn-group btn-group-sm" role="group">
                                <a class="btn btn-primary" onclick="vm.takelook.initSendSite(); vm.takelook.initTakelook();"><span class="glyphicon glyphicon-refresh"></span></a>
                                <button id="btn_takelook_prev_flow" type="button" class="btn btn-danger" disabled>返回上个流程</button>
                                @*<button id="btn_add_repoert" type="button" class="btn btn-danger">销售日报</button>*@
                                <button id="btn_takelook" type="button" class="btn btn-info">带看场地申请</button>
                                <button id="btn_takelook_next_flow" type="button" class="btn btn-danger" disabled>带看反馈</button>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                </div>
                <table class="table table-condensed table-bordered table-hover">
                    <thead>
                        <tr>
                            <td>订单号</td>
                            <td>批次号</td>
                            <td>客户名称</td>
                            <td>联系电话</td>
                            <td>公司名称</td>
                            <td>场地名称</td>
                            <td>跟进人</td>
                            <td>创建时间</td>
                            <td>操作</td>
                        </tr>
                    </thead>
                    <tbody id="takelookGrid"></tbody>
                </table>
            </div>

            <table class="table table-condensed table-bordered table-hover">
                <thead>
                    <tr>
                        <td width="50">序号</td>
                        <td width="200">场地名称</td>
                        <td>开始时间</td>
                        <td>结束时间</td>
                    </tr>
                </thead>
                <tbody id="previewTime"></tbody>
            </table>

            <table class="table table-condensed table-bordered table-hover">
                <thead>
                    <tr>
                        <td width="50">序号</td>
                        <td width="200">场地名称</td>
                        <td>部门</td>
                        <td>陪同人员</td>
                    </tr>
                </thead>
                <tbody id="previewPeople"></tbody>
            </table>


            <table class="table table-condensed table-bordered table-hover">
                <thead>
                    <tr>
                        <td width="50">序号</td>
                        <td width="200">场地名称</td>
                        <td>资源</td>
                        <td>车辆信息信息</td>
                        <td>司机</td>
                    </tr>
                </thead>
                <tbody id="previewCar"></tbody>
            </table>

        </div>

        @*意向场地确认*@
        <div role="tabpanel" class="tab-pane state-content" id="state3">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <div>
                        <div class="pull-left"><span class="h5">意向场地列表</span></div>
                        <div class="pull-right">
                            <div class="btn-group btn-group-sm" role="group">
                                <a class="btn btn-primary" onclick="vm.intentionsite.initIntentionService();vm.intentionsite.initIntentionSite();"><span class="glyphicon glyphicon-refresh"></span></a>
                                @*<button id="btn_add_repoert" type="button" class="btn btn-danger">销售日报</button>*@
                                <button id="btn_intentionsite" type="button" class="btn btn-info">申请场地报价</button>
                                @*<button id="btn_intentionsite_next_flow" type="button" class="btn btn-danger">跳转下个流程</button>*@
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                </div>
                <table class="table table-condensed table-bordered table-hover">
                    <thead>
                        <tr>
                            <td></td>
                            <td>订单号</td>
                            <td>批次号</td>
                            <td>活动名称</td>
                            <td>城市</td>
                            <td>场地名称</td>
                            <td>联系人</td>
                            <td>联系电话</td>
                            <td>公司</td>
                            <td>预约时间</td>
                            <td>跟进人</td>
                            <td>创建时间</td>
                        </tr>
                    </thead>
                    <tbody id="intentionSiteGrid"></tbody>
                </table>
            </div>

            <div class="panel panel-default">
                <div class="panel-heading">
                    <div>
                        <div class="pull-left"><span class="h5">配套服务</span></div>
                        <div class="pull-right">
                            <button id="btn_intentionsite_service" type="button" class="btn btn-primary btn-sm">添加配套报价</button>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                </div>
                <table class="table table-condensed table-bordered table-hover">
                    <thead>
                        <tr>
                            <td>编号</td>
                            <td>场地名称</td>
                            <td>配套服务</td>
                            <td>价格(元)</td>
                            <td>价格单位</td>
                            <td>数量</td>
                            <td>服务描述</td>
                            <td>操作</td>
                        </tr>
                    </thead>
                    <tbody id="intentionServiceGrid"></tbody>
                </table>
            </div>
        </div>

        @*价格谈判*@
        <div role="tabpanel" class="tab-pane state-content" id="state4">

            <div class="panel panel-default">
                <div class="panel-heading">
                    <div>
                        <div class="pull-left"><span class="h5">报价单</span></div>
                        <div class="pull-right">
                            <div class="btn-group btn-group-sm" role="group">
                                <a class="btn btn-primary" onclick="vm.pricetalks.initPriceTalks();"><span class="glyphicon glyphicon-refresh"></span></a>
                                @*<button id="btn_pricetalks_addprice" type="button" class="btn btn-info">场地报价申请</button>*@
                                @*<button id="btn_add_repoert" type="button" class="btn btn-danger">销售日报</button>*@
                                <button id="btn_pricetalks_sendprice" type="button" class="btn btn-info">发送审核报价单</button>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                </div>
                <table class="table table-condensed table-bordered table-hover">
                    <thead>
                        <tr>
                            <td></td>
                            <td width="230">订单号</td>
                            <td>批次号</td>
                            <td>城市</td>
                            <td>场地名称</td>
                            <td>活动类型</td>
                            <td>公司名称</td>
                            <td>活动主题</td>
                            <td width="130">预约时间</td>
                            @*<td>场租(元/天)</td>*@
                            <td>配套服务</td>
                            @*<td>报价单</td>*@
                            <td>创建时间</td>
                            <td>操作</td>
                        </tr>
                    </thead>
                    <tbody id="priceTalksGrid"></tbody>
                </table>
            </div>

        </div>

        @*场地预定*@
        <div role="tabpanel" class="tab-pane state-content" id="state5">

            <div class="panel panel-default">
                <div class="panel-heading">
                    <div>
                        <div class="pull-left"><span class="h5">场地预定清单</span></div>
                        <div class="pull-right">
                            <div class="btn-group btn-group-sm" role="group">
                                <a class="btn btn-primary" onclick="vm.reservesite.initReserveSite();"><span class="glyphicon glyphicon-refresh"></span></a>
                                @*<button id="btn_add_repoert" type="button" class="btn btn-danger">销售日报</button>*@
                                <button id="btn_reservesite_add" type="button" class="btn btn-info">场地预定</button>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                </div>
                <table class="table table-condensed table-bordered table-hover">
                    <thead>
                        <tr>
                            <td></td>
                            <td>订单号</td>
                            <td>批次号</td>
                            <td>城市</td>
                            <td>场地名称</td>
                            <td>预定时间</td>
                            @*<td>状态</td>*@
                            <td>跟进人</td>
                            <td>创建时间</td>
                        </tr>
                    </thead>
                    <tbody id="reserveSiteGrid"></tbody>
                </table>
            </div>

        </div>

        @*用印申请*@
        <div role="tabpanel" class="tab-pane state-content" id="state6">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <div class="pull-left"><span class="h5">用印申请</span></div>
                    <div class="pull-right">
                        <div class="btn-group btn-group-sm" role="group">
                            <a class="btn btn-primary" onclick="vm.impress.initImpress();"><span class="glyphicon glyphicon-refresh"></span></a>
                            @*<button id="btn_add_repoert" type="button" class="btn btn-danger">销售日报</button>*@
                            <button id="btn_impress_add" type="button" class="btn btn-info">申请盖章</button>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <table class="table table-condensed table-bordered table-hover">
                    <thead>
                        <tr>
                            <td>订单号</td>
                            <td>批次号</td>
                            <td>城市</td>
                            <td>场地</td>
                            <td>客户合同</td>
                            <td>场地合同</td>
                            <td>状态</td>
                            <td>创建时间</td>
                        </tr>
                    </thead>
                    <tbody id="impressGrid"></tbody>
                </table>
            </div>

        </div>

        @*签订合同*@
        <div role="tabpanel" class="tab-pane state-content" id="state7">

            <div class="panel panel-default">
                <div class="panel-heading">
                    <div class="pull-left"><span class="h5">场地活动订单</span></div>
                    <div class="pull-right">
                        <div class="btn-group btn-group-sm" role="group">
                            <a class="btn btn-primary" onclick="vm.signcontract.initSignContract();"><span class="glyphicon glyphicon-refresh"></span></a>
                            
                            <button id="btn_signcontract_add" type="button" class="btn btn-info">订单结束，转合同单</button>
                            @*<button id="btn_signcontract_stop" type="button" class="btn btn-primary">订单终止</button>*@
                        </div>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <table class="table table-condensed table-bordered table-hover">
                    <thead>
                        <tr>
                            <td></td>
                            <td>订单号</td>
                            <td>批次号</td>
                            <td>城市</td>
                            <td>场地名称</td>
                            <td>预定时间</td>
                            <td>跟进人</td>
                            <td>上传电子合同</td>
                            <td>创建时间</td>
                        </tr>
                    </thead>
                    <tbody id="signContractGrid"></tbody>
                </table>
            </div>

        </div>
    </div>
</div>

<div class="modal fade" id="loadingModal">
    <div style="width: 200px;height:20px; z-index: 20000; position: absolute; text-align: center; left: 50%; top: 50%;margin-left:-100px;margin-top:-10px">
        <div class="progress progress-striped active" style="margin-bottom: 0;">
            <div class="progress-bar" style="width: 100%;"></div>
        </div>
        <h5 style="color:#f0ad4e"> <strong>正在发送...下载PPT大概需花费1分钟，请稍等！</strong> </h5>
    </div>
</div>
<style>
    .first {
        font-weight: bold;
    }

    .first-node {
        margin-left: 30px;
    }

    .btn-select select option {
        font-weight: bold;
    }

    .btn-select:hover .cur-select {
        background-color: #f90;
    }

    .btn-select select {
        position: absolute;
        top: 0;
        left: 0;
        width: 150px;
        height: 25px;
        opacity: 0;
        filter: alpha(opacity: 0;
        );
        font: 14px/20px "Microsoft YaHei";
        color: #f80;
    }

        .btn-select select option {
            text-indent: 10px;
        }

            .btn-select select option:hover {
                background-color: #f80;
                color: #fff;
            }
    .dropdown-menu > li > a {
        
        padding: 5px 20px;
        clear: both;
        font-weight: 400;
        line-height: 1.42857143;
        color: #475059;
        white-space: nowrap;
    }
</style>
<script>
    // from page type
    var pageType = $.request("pageType");
    var type = $.request("type");
    var orderId = $.request('orderid');
    var isread = $.request('isread');
    var F_DemandId = $.request('F_DemandId');
    function find_checkbox(success, error) {
        var $gridList = this;
        var checkboxs = $gridList.find("input[type='checkbox']:checked"),
            selectedVals = [];
        if (checkboxs.length) {
            checkboxs.each(function (n, ele) { selectedVals.push(ele.value); });
            success && success(selectedVals);
        } else {
            error && error();
        }
    }
    function valid_checkbox() {
        var args = Array.prototype.slice.call(arguments);
        if (args.length == 1) {
            args.push(function () {
                $.modalAlert("请选择相关的订单项", "success");
            });
        }
        find_checkbox.apply(this, args)
    }
    function loadReserveSite(orderId, callback) {
        $.ajax({
            url: "/OrderFlowManage/ClientOrder/GetReserveSiteByOrderJson?orderId=" + orderId,
            data: {},
            dataType: "json",
            async: false,
            success: function (data) {
                callback && callback(data.rows);
            }
        });
    }

    function reloadPage(pageNum) {
        if (pageNum === undefined) {
            location.href = location.href;
        } else {
            // 根据指定的索引跳转相关页面
            //location.href = location.href.substr(0, location.href.length - 1) + pageNum;
            location.href = location.href.replace(/type=\d/, "type=" + pageNum);
        }
    }

    var vm = {
        orderInfo: null,
        units: [],  /*场地价格单位集*/
        citys: [],  /*城市*/
        //areas: [],  /*区域*/
        //businessareas: [],  /*商圈*/
        order: {    /*基本订单信息*/
            initControl: function (orderInfo) {
                if (!orderInfo) return;
                // F_OrderState             订单阶段:0:待指派,1:场地推荐,2:带看场地,3:意向场地,4:价格协商,5:场地预定,6:签订合同, 7 用印申请, 8:订单完成
                // F_OrderStateProcess      当前状态的进度,-1等待跟进，0:等待确认,1:通过,2:驳回
                var $siteSaveFlow = $("#btn_sitesave_flow"),
                    $siteSave = $("#btn_sitesave"),
                    // 2
                    $takelookPrevFlow = $("#btn_takelook_prev_flow"),
                    $takelook = $("#btn_takelook"),
                    $takelookNextFlow = $("#btn_takelook_next_flow"),

                    // 3
                    $intentionsite = $("#btn_intentionsite"),
                    $intentionsiteService = $("#btn_intentionsite_service"),

                    // 4/5
                    $pricetalksAddprice = $("#btn_pricetalks_addprice"),
                    $pricetalksSendprice = $("#btn_pricetalks_sendprice"),
                    // 6
                    $reservesiteAdd = $("#btn_reservesite_add"),
                    // 7
                    $impressAdd = $("#btn_impress_add"),
                    // 8
                    $signcontractAdd = $("#btn_signcontract_add");
                // 管理人员
                //if (pageType == "all") {
                //    $siteSave.hide();
                //    $siteSaveFlow.hide();
                //    $takelookPrevFlow.hide();
                //    $takelook.hide();
                //    $intentionsite.hide();
                //    $intentionsiteService.hide();
                //    $pricetalksAddprice.hide();
                //    $pricetalksSendprice.hide();
                //    $reservesiteAdd.hide();
                //    $impressAdd.hide();
                //    $signcontractAdd.hide();
                //} else {
                $siteSaveFlow.prop("disabled", false);

                $takelook.prop("disabled", false);
                //$takelookNextFlow.prop("disabled", true);

                $takelookNextFlow.prop("disabled", false);

                $pricetalksAddprice.prop("disabled", false);
                $pricetalksSendprice.prop("disabled", false);
                $intentionsite.prop("disabled", false);
                //$intentionsiteService.prop("disabled", true);
                $intentionsiteService.prop("disabled", false);
                $reservesiteAdd.prop("disabled", true);
                $impressAdd.prop("disabled", true);
                $signcontractAdd.prop("disabled", true);

                if (orderInfo.F_OrderState == 1) {
                    // 场地推荐(场地档期审核)中订单子状态为 1通过状态时，可以跳转下一流程的处理逻辑
                    $siteSaveFlow.prop("disabled", orderInfo.F_OrderStateProcess < 0);
                } else if (orderInfo.F_OrderState == 2) {
                    //$takelookPrevFlow.prop("disabled", false);
                    //$takelook.prop("disabled", orderInfo.F_OrderStateProcess != -1);
                    //$takelookNextFlow.prop("disabled", orderInfo.F_OrderStateProcess < 0);
                } else if (orderInfo.F_OrderState == 3) {
                    //$intentionsite.prop("disabled", orderInfo.F_OrderStateProcess != -1);
                    //$intentionsiteService.prop("disabled", orderInfo.F_OrderStateProcess != -1);
                } else if (orderInfo.F_OrderState == 4) {
                    $pricetalksAddprice.prop("disabled", false);
                    $pricetalksSendprice.prop("disabled", false);
                } else if (orderInfo.F_OrderState == 5) {
                    $reservesiteAdd.prop("disabled", orderInfo.F_OrderStateProcess != -1);
                } else if (orderInfo.F_OrderState == 6) {
                    $impressAdd.prop("disabled", orderInfo.F_OrderStateProcess > 0);
                } else if (orderInfo.F_OrderState == 7) {
                    $signcontractAdd.prop("disabled", orderInfo.F_OrderStateProcess > 0);
                } else if (orderInfo.F_OrderState == 8) {

                }
                //}
            },
            //next: function () {
            //    $.modalOpen({
            //        id: "OrderNext",
            //        title: "订单状态变更",
            //        url: "/OrderFlowManage/ClientOrder/OrderNext",
            //        width: "700px",
            //        height: "520px",
            //        callBack: function (iframeId) {
            //            //top.frames[iframeId].submitForm();
            //        }
            //    });
            //},
            close: function () {
                var frameid = $.request('frameid');
                $.modalOpen({
                    id: "ShowOrderClose",
                    title: "关闭订单",
                    url: "/OrderFlowManage/ClientOrder/ShowOrderClose?keyValue=" + orderId + '&frameid=' + frameid,
                    width: "700px",
                    height: "380px",
                    btn: ["确定关闭", "取消"],
                    callBack: function (iframeId) {
                        top.frames[iframeId].submitForm();
                    }
                });
            },
            report: function () {
                $.modalOpen({
                    id: "reportHistoryList",
                    title: "日报历史记录",
                    url: "/OrderFlowManage/ClientOrder/OrderReportList?F_DemandId=" + F_DemandId + "&type=1",
                    width: "800px",
                    height: "600px",
                    callBack: function (iframeId) {
                        top.frames[iframeId].submitForm();
                    },
                    btn: null
                });
            },
            write: function () {
                var tabType = parseInt($.request('type'));
                $.modalOpen({
                    id: "salesreport",
                    title: "销售日报",
                    url: "/OrderFlowManage/ClientOrder/OrderTrackingReport?orderId=" + $.request('orderid') + "&F_OrderStep=" + tabType + "",
                    width: "800px",
                    height: "600px",
                    callBack: function (iframeId) {
                        top.frames[iframeId].submitForm();
                    }
                });
            },
            initOrderInfo: function (result) {
                $.ajax({
                    url: "/OrderFlowManage/ClientOrder/GetOrderInfoJson",
                    data: { keyValue: orderId, isread: isread },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        if (data) {
                            // 处理多个城市的需求。
                            var arr = data.F_ActivityCityId.indexOf(',') == -1 ? [data.F_ActivityCityId] : data.F_ActivityCityId.split(',');
                            var citys = [];
                            for (var i = 0; i < result.City.length; i++) {
                                var ele = result.City[i];
                                for (var j = 0; j < arr.length; j++) {
                                    var val = arr[j];
                                    if (val == ele.Value) {
                                        citys.push(ele.Text);
                                    }
                                }
                            }
                            data.F_ActivityCityName = citys.toString();
                            data.F_ActivityStartDate = data.F_ActivityStartDate == null ? '' : data.F_ActivityStartDate.split(' ')[0];
                            data.F_ActivityEndDate = data.F_ActivityEndDate == null ? '' : data.F_ActivityEndDate.split(' ')[0];
                            data.F_BuildDate = data.F_BuildDate == null ? '' : data.F_BuildDate.split(' ')[0];

                            $("#baseForm").formSerialize(data);
                            vm.orderInfo = data;
                            vm.order.initControl(data);
                            // 城市 区域 商圈 绑定数据(多选择框)
                            vm.sendsite.bindMultipleSelectControl($("#F_ActivityCityId"), result.City, "", data.F_ActivityCityId);
                            vm.sendsite.bindMultipleSelectControl($("#txt_cityid"), result.City, "", data.F_ActivityCityId, function (selectValue) {
                                vm.sendsite.bindDistrict(selectValue);
                                vm.sendsite.bindArea();
                            });
                            vm.sendsite.bindDistrict(data.F_ActivityCityId, "", function (selectValue) {
                                vm.sendsite.bindArea(selectValue);
                            });
                            vm.sendsite.bindArea();

                            //vm.sendsite.bindSelectControl($("#txt_acttype"), result.ActivityType, "==全部活动==", data.F_ActivityType);
                            vm.sendsite.bindSelectControl($("#txt_sitetype"), result.SiteType, "", data.F_SiteType);
                            //vm.sendsite.bindSelectControl($("#F_ActivityType"), result.ActivityType, "==请选择活动类型==", data.F_ActivityType);
                            vm.sendsite.bindSelectControl($("#F_SiteType"), result.SiteType, "==请选择场地类型==", data.F_SiteType);
                            vm.sendsite.bindSelectControl($("#F_PositionId"), result.Position, "==请选择公司职位==", data.F_PositionId);
                            vm.sendsite.bindSelectControl($("#F_DepartmentId"), result.Department, "==请选择所属部门==", data.F_DepartmentId);

                            if (result.FirstActivityType != null) {
                                var Event_type = "";
                                for (var j = 0; j < result.FirstActivityType.length; j++) {
                                    var selected1 = result.FirstActivityType[j].Value == data.F_ActivityType ? 'selected' : '';
                                    Event_type += "<option value='" + result.FirstActivityType[j].Value + "' " + selected1 + " style=\"font-weight:bold;\">" + result.FirstActivityType[j].Text + "</option >";
                                    for (var i = 0; i < result.ActivityType.length; i++) {
                                        if (result.ActivityType[i].F_Description == result.FirstActivityType[j].Value) {
                                            var selected2 = result.ActivityType[i].Value == data.F_ActivityType ? 'selected' : '';
                                            Event_type += "<option value='" + result.ActivityType[i].Value + "' " + selected2 + ">&nbsp;&nbsp;" + result.ActivityType[i].Text + "</option>";
                                        }
                                    }
                                }

                                $("#F_ActivityType").html("<option value=''>==请选择活动类型==</option >" + Event_type);
                                $("#txt_acttype").html("<option value=''>==全部活动==</option >" + Event_type);
                                $("#F_ActivityType,#txt_acttype").select2();
                            }

                            $("#F_ActivityType,#txt_acttype").val(data.F_ActivityType);
                            $("#txt_area").val(data.F_SiteArea);

                            $("#baseForm").show();
                        }
                    }
                });
            },
            init: function () {
                var sendsite = vm.sendsite;
                var itemList = getCache("TypeList");
                if (!itemList || itemList.length <= 0) {
                    $.ajax({
                        url: "/OrderFlowManage/ClientOrder/GetItemsJson",
                        data: {},
                        dataType: "json",
                        async: false,
                        success: function (data) {
                            if (data) {
                                setCache("TypeList", data);
                                vm.units = data.Units;
                                vm.citys = data.City;

                                //vm.areas = data.Areas;
                                //vm.businessareas = data.BusinessAreas;
                                // 初始化订单的信息
                                vm.order.initOrderInfo(data);
                            }
                        }
                    });
                }
                else {
                    vm.units = itemList.Units;
                    vm.citys = itemList.City;
                    vm.order.initOrderInfo(itemList);
                }
            }
        },
        flow: { /*流程流转记录*/
            getOrderCheckRecordList: function () {
                $.ajax({
                    url: "/OrderFlowManage/ClientOrder/GetOrderCheckRecordList",
                    data: { orderId: orderId },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        var html = [],
                            appTypes = ["", "场地档期审核", "场地带看申请", "场地意向确认", "价格协商报价单申请", "价格协商报价单审核", "场地预定申请", "合同审核", "需求单完成"],
                            states = ["驳回", "通过"];
                        if (data && data.rows.length) {
                            for (var i = 0; i < data.rows.length; i++) {
                                var item = data.rows[i];
                                html.push("<tr><td>");
                                html.push(appTypes[item.F_ApplyType]);
                                html.push("</td><td>");
                                html.push(item.F_CreatorTime);
                                html.push("</td><td>");
                                html.push(item.F_CheckContent);
                                html.push("</td><td>");
                                html.push(item.F_CheckUserName);
                                html.push("</td><td>");
                                html.push(item.F_State ? states[item.F_State] : "");
                                html.push("</td><td>");
                                html.push(item.F_CheckTime);
                                html.push("</td><td>");
                                html.push(item.F_Note);
                                html.push("</td></tr>");
                            }
                        } else {
                            html.push("<tr><td  colspan='7' style='color: red'>没有相关的数据</td></tr>");
                        }
                        $("#gridOrderCheckRecordList").html(html.join(''));
                    }
                });
            },
            getOrderRecommendList: function () {
                $.ajax({
                    url: "/OrderFlowManage/ClientOrder/GetOrderRecommendList?orderId=" + orderId,
                    data: { orderId: orderId },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        var html = [];
                        if (data && data.rows.length) {
                            for (var i = 0; i < data.rows.length; i++) {
                                var item = data.rows[i];
                                html.push("<tr><td>");
                                html.push(item.F_Title);
                                html.push("</td><td>");
                                html.push(item.F_SpaceTitle);
                                html.push("</td><td>");
                                html.push(item.F_CreatorTime);
                                html.push("</td><td>");
                                html.push(item.F_Remark);
                                html.push("</td></tr>");
                            }
                        } else {
                            html.push("<tr><td  colspan='4' style='color: red'>没有相关的数据</td></tr>");
                        }
                        $("#gridOrderRecommendList").html(html.join(''));
                    }
                });
            },
            getOrderTakelookList: function () {
                $.ajax({
                    url: "/OrderFlowManage/ClientOrder/GetOrderTakelookList",
                    data: { orderId: orderId },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        var html = [];
                        if (data && data.rows.length) {
                            for (var i = 0; i < data.rows.length; i++) {
                                var item = data.rows[i];
                                html.push("<tr><td>");
                                html.push(item.F_Title);
                                html.push("</td><td>");
                                html.push(item.Mocha_ITOMName);
                                html.push("</td><td>");
                                html.push(item.F_Source);
                                html.push("</td><td>");
                                html.push(item.F_FlowUserName);
                                html.push("</td><td>");
                                html.push(item.F_CreatorTime);
                                html.push("</td><td>");
                                html.push(item.F_Remark);
                                html.push("</td></tr>");
                            }
                        } else {
                            html.push("<tr><td  colspan='6' style='color: red'>没有相关的数据</td></tr>");
                        }
                        $("#gridOrderTakelookList").html(html.join(''));
                    }
                });
            },
            init: function () {
                vm.flow.getOrderCheckRecordList();
                vm.flow.getOrderRecommendList();
                vm.flow.getOrderTakelookList();
            }
        },
        sendsite: { // 推荐场地
            initSelectControl: function () {
                var $gridList = $("#gridList");

                $("#btn_site_reset").click(vm.sendsite.resetSearch);
                $("#btn_search").click(vm.sendsite.bindSearch);
                $("#btn_sitesave").click(function () {
                    var li = $('#menu').children();
                    if (li.length > 0) {
                        var siteAndSpaceIds = [];
                        for (var i = 0; i < li.length; i++) {
                            siteAndSpaceIds.push($(li[i]).attr('value'));
                        }
                        var formId = $("#F_WorkFormId").val();
                        $.submitForm({
                            url: "/OrderFlowManage/ClientOrder/SubmitSendSiteForm?keyValue=" + orderId,
                            param: { OrderId: orderId, SiteIds: siteAndSpaceIds, FlowFormId: formId },
                            success: function (data) {
                                $("#btn_sitesave").prop("disabled", true).text("咨询档期/价格");
                                $('#menu').empty();
                                $("#gridList").trigger("reloadGrid");
                            }
                        });
                    } else {
                        $.modalAlert("请选择相关的订单项", "success");
                    }

                });
                $("#btn_sitesave_flow").click(function () {
                    $.modalOpen({
                        id: "ShowSendSite",
                        title: "场地审核结果",
                        url: "/OrderFlowManage/ClientOrder/ShowSendSite?keyValue=" + orderId,
                        width: "1000px",
                        height: "400px",
                        //btn: vm.orderInfo.F_OrderState < 2 ? ["确认", "取消"] : [],
                        callBack: function (iframeId) {
                            top.frames[iframeId].submitForm();
                        }
                    });
                });
                $("#btn_add_demand").click(function () {
                    $.modalOpen({
                        id: "SiteDemand",
                        title: "新增场地需求",
                        url: "/SiteManage/SiteDemand/Form?keyValue=SiteDemand",
                        width: "800px",
                        height: "600px",
                        callBack: function (iframeId) {
                            top.frames[iframeId].submitForm();
                        }
                    });
                });

                //$("#btn_add_repoert").click(function () {
                //    var tabType = parseInt($.request('type'));
                //    $.modalOpen({
                //        id: "salesreport",
                //        title: "销售日报",
                //        url: "/OrderFlowManage/ClientOrder/OrderTrackingReport?orderId=" + $.request('orderid') + "&F_OrderStep=" + tabType + "",
                //        width: "800px",
                //        height: "600px",
                //        callBack: function (iframeId) {
                //            top.frames[iframeId].submitForm();
                //        }
                //    });
                //});

                $('#btn_email').click(function () {
                    var Email = $('#F_Mail').val();
                    var Phone = $('#F_Phone').val();
                    if ($.trim(Email).length > 0 || $.trim(Phone).length > 0) {
                        valid_checkbox.call($gridList, function (siteAndSpaceIds) {
                            if ($.trim(Email).length == 0 || $.trim(Phone).length == 0) {
                                var opts = { btn: ['是', '否'] };
                                $.modalConfirm("短信或邮箱有为空,确定发送吗？", function (flag) {
                                    if (flag) {

                                        $("#loadingModal").modal('show');
                                        var F_Contact = $('#F_Contact').val();
                                        var F_ActivityTheme = $('#F_ActivityTheme').val();
                                        $.ajax({
                                            url: "/OrderFlowManage/ClientOrder/SendSpaceEmail",
                                            type: "Post",
                                            data: { SpaceIds: siteAndSpaceIds.toString(), ToEmail: Email, Contact: F_Contact, ActivityName: F_ActivityTheme, Phone: Phone },
                                            dataType: "json",
                                            async: true,
                                            success: function (obj) {
                                                if (obj.state == "error") {
                                                    if (obj.message == "您未设置邮箱密码") {
                                                        $.modalConfirm("您未设置邮箱密码,是否去设置？", function (flag, index) {
                                                            $.modalConfirmClose(index);

                                                            if (flag) {
                                                                $('.layui-layer-btn a.btn-danger').click();
                                                                var url = "/SystemManage/User/Info";
                                                                $.addTab({
                                                                    href: url,
                                                                    text: '个人信息',
                                                                    index: 999
                                                                });

                                                            }
                                                        });
                                                    } else {
                                                        alert(obj.message);
                                                    }
                                                } else {
                                                    $.modalAlert('发送成功');
                                                }
                                                $("#loadingModal").modal('hide');
                                            },
                                            error: function () {
                                                $("#loadingModal").modal('hide');
                                            }
                                        });
                                    }
                                }, opts);
                            } else {
                                $("#loadingModal").modal('show');
                                var F_Contact = $('#F_Contact').val();
                                var F_ActivityTheme = $('#F_ActivityTheme').val();
                                $.ajax({
                                    url: "/OrderFlowManage/ClientOrder/SendSpaceEmail",
                                    type: "Post",
                                    data: { SpaceIds: siteAndSpaceIds.toString(), ToEmail: Email, Contact: F_Contact, ActivityName: F_ActivityTheme, Phone: Phone },
                                    dataType: "json",
                                    async: true,
                                    success: function (obj) {
                                        if (obj.state == "error") {
                                            if (obj.message == "您未设置邮箱密码") {
                                                $.modalConfirm("您未设置邮箱密码,是否去设置？", function (flag) {
                                                    if (flag) {
                                                        var index = parent.layer.getFrameIndex(window.name);
                                                        parent.layer.close(index);
                                                        var url = "/SystemManage/User/Info";
                                                        $.addTab({
                                                            href: url,
                                                            text: '个人信息',
                                                            index: 999
                                                        });
                                                    }
                                                });
                                            } else {
                                                alert(obj.message);
                                            }
                                        } else {
                                            $.modalAlert('发送成功');
                                        }
                                        $("#loadingModal").modal('hide');
                                    },
                                    error: function () {
                                        $("#loadingModal").modal('hide');
                                    }
                                });
                            }
                        });
                    } else {
                        $.modalAlert("未绑定公司邮箱和联系电话", "success");
                    }
                });

                $('#btn_flowtake').click(function () {
                    valid_checkbox.call($gridList, function (siteAndSpaceIds) {
                        console.log(siteAndSpaceIds.toString());
                        $.modalOpen({
                            id: "flowtake",
                            title: "流程跳转",
                            url: "/OrderFlowManage/ClientOrder/OrderFlowTake?orderId=" + $.request('orderid') + "&siteSpace=" + siteAndSpaceIds.toString(),
                            width: "1500px",
                            height: "600px",
                            callBack: function (iframeId) {
                                top.frames[iframeId].submitForm();
                            }
                        });
                    });
                });
            },
            resetSearch: function () {
                $("#txt_keyword, #txt_minmoney, #txt_maxmoney, #txt_area").val('');
                $("#txt_acttype").select2("val", "");
                $("#txt_cityid, #txt_districtid, #txt_business_area, #txt_sitetype").select2("val", "");
            },
            bindSearch: function () {
                var $gridList = $("#gridList");
                var queryJson = {
                    keyword: $("#txt_keyword").val(),
                    cityid: ($("#txt_cityid").val() || "").toString(),
                    districtid: ($("#txt_districtid").val() || "").toString(),
                    businessarea: ($("#txt_business_area").val() || "").toString(),
                    acttype: $("#txt_acttype").val(),
                    minmoney: $("#txt_minmoney").val(),
                    maxmoney: $("#txt_maxmoney").val(),
                    area: $("#txt_area").val(),
                    sitetype: ($("#txt_sitetype").val() || []).toString()
                };
                //console.log('bindSearch site:',queryJson);
                $gridList.jqGrid('setGridParam', {
                    postData: { queryJson: JSON.stringify(queryJson) },
                }).trigger('reloadGrid');
            },
            bindSelectControl: function (dom, data, placeholder, selectedValue) {
                var html = placeholder ? '<option value="" >' + placeholder + '</option>' : '';
                for (var i = 0; i < data.length; i++) {
                    html += '<option value="' + data[i].Value + '" ' + (selectedValue == data[i].Value ? "selected" : "") + '>' + data[i].Text + '</option>';
                }
                dom.html(html)
                //dom.bindSelect();
                dom.select2();
            },
            bindMultipleSelectControl: function (dom, data, placeholder, selectedValue, callback) {
                var html = placeholder ? '<option value="" >' + placeholder + '</option>' : '',
                    selectedValues = selectedValue.split(',');
                for (var i = 0; i < data.length; i++) {
                    var selected = false;
                    for (var j = 0; j < selectedValues.length; j++) {
                        var item = selectedValues[j];
                        if (item == data[i].Value) {
                            selected = true;
                        }
                    }
                    html += '<option value="' + data[i].Value + '" ' + (selected ? "selected" : "") + '>' + data[i].Text + '</option>';
                }
                dom.html(html)
                //dom.bindSelect();
                dom.select2({ multiple: true });
                if (callback) {
                    dom.on("select2:select", function () {
                        callback($(this).val());
                    });
                    dom.on("select2:unselect", function () {
                        callback($(this).val());
                    });
                }
            },
            bindOtherMultipleSelectControl: function (dom, data, placeholder, selectedValue, callback) {
                var html = placeholder ? '<option value="" >' + placeholder + '</option>' : '',
                    selectedValues = (selectedValue || "").split(',');
                for (var i = 0; i < data.length; i++) {
                    var selected = false;
                    for (var j = 0; j < selectedValues.length; j++) {
                        var item = selectedValues[j];
                        if (item == (data[i].F_EnCode || data[i].F_Id)) {
                            selected = true;
                        }
                    }
                    html += '<option value="' + (data[i].F_EnCode || data[i].F_Id) + '" ' + (selected ? "selected" : "") + '>' + data[i].F_FullName + '</option>';
                }
                dom.html(html)
                //dom.bindSelect();
                dom.select2({ multiple: true });
                dom.on("select2:select", function () {
                    var data = $(this).val();
                    callback && callback(data);
                });
            },
            bindChecked: function (ele) {
                if (ele.checked) {
                    var c = $(ele);
                    var name = c.parent().parent().children().eq(5).text();
                    var siteandspace = c.val();
                    var li = $('#menu').children();
                    var b = true;
                    for (var i = 0; i < li.length; i++) {
                        if ($(li[i]).attr('value') == $(ele).val()) {
                            ; b = false;
                            break;k
                        }
                    }
                    if (b)
                        $('#menu').append("<li style='margin: 5px;' value='" + siteandspace + "' ><a onclick='vm.sendsite.searchsite(this)' style='display:inline;'>" + name + "</a><a style='display: inline;' onclick='vm.sendsite.removesite(this)'>X</a></li>");
                } else {
                    var li = $('#menu').children();
                    for (var i = 0; i < li.length; i++) {
                        if ($(li[i]).attr('value') == $(ele).val()) {
                            $(li[i]).remove();
                        }
                    }
                }
                if ($('#menu').children().length > 0) {
                    $("#btn_sitesave").prop("disabled", false).text("咨询档期/价格(" + $('#menu').children().length + ")");
                }
                else{
                    $("#btn_sitesave").prop("disabled", true).text("咨询档期/价格");
                }
            },
            searchsite: function (ele) {
                $('#txt_keyword').val($(ele).text().split('-')[0]);
                $('#btn_search').click();
            },
            removesite: function (ele) {
                $(ele).parent().remove();
                if ($('#menu').children().length > 0) {
                    $("#btn_sitesave").prop("disabled", false).text("咨询档期/价格(" + $('#menu').children().length + ")");
                }
                else {
                    $("#btn_sitesave").prop("disabled", true).text("咨询档期/价格");
                }
                
            },
            bindDistrict: function (parentIds, selectedValue, callback) {
                if (parentIds) {
                    $.ajax({
                        url: "/OrderFlowManage/ClientOrder/GetAreasJson?parentIds=" + parentIds,
                        data: { parentIds: parentIds },
                        dataType: "json",
                        async: false,
                        success: function (data) {
                            data && vm.sendsite.bindOtherMultipleSelectControl($("#txt_districtid"), data, "", selectedValue, callback);
                        }
                    });
                } else {
                    $("#txt_districtid").html("").select2({ multiple: true });
                    //$("#txt_districtid").on("select2:select", function () {
                    //    var data = $(this).val();
                    //    callback && callback(data);
                    //});
                }
            },
            bindSiteType: function (parentIds, selectedValue, callback) {
            },
            bindArea: function (parentIds, selectedValue, callback) {
                if (parentIds) {
                    $.ajax({
                        url: "/OrderFlowManage/ClientOrder/GetBusinessAreasJson?parentIds=" + parentIds,
                        data: { parentIds: parentIds },
                        dataType: "json",
                        async: false,
                        success: function (data) {
                            data && vm.sendsite.bindOtherMultipleSelectControl($("#txt_business_area"), data, "", selectedValue, callback);
                        }
                    });
                } else {
                    $("#txt_business_area").html("").select2({ multiple: true });
                    //$("#txt_business_area").on("select2:select", function () {
                    //    var data = $(this).val();
                    //    callback && callback(data);
                    //});
                }
            },
            bindSiteDetail: function (keyValue) {
                $.modalOpen({
                    id: "details",
                    title: "场地详情",
                    url: "/SiteManage/Site/Details?keyValue=" + keyValue,
                    width: "1200px",
                    height: "650px",
                    btn: null,
                });
            },
            init: function () {
                vm.sendsite.initSelectControl();

                var queryJson = {
                    keyword: $("#txt_keyword").val(),
                    cityid: ($("#txt_cityid").val() || "").toString(),
                    districtid: ($("#txt_districtid").val() || "").toString(),
                    businessarea: ($("#txt_business_area").val() || "").toString(),
                    acttype: $("#txt_acttype").val(),
                    minmoney: $("#txt_minmoney").val(),
                    maxmoney: $("#txt_maxmoney").val(),
                    area: $("#txt_area").val(),
                    sitetype: ($("#txt_sitetype").val() || []).toString()
                };
                //console.log(queryJson);

                var $gridList = $("#gridList");
                $gridList.dataGrid({
                    url: "/OrderFlowManage/ClientOrder/GetSiteGridJson",
                    height: $(window).height() - 476,
                    postData: { queryJson: JSON.stringify(queryJson) },
                    colModel: [
                        {
                            label: '选择', name: 'F_SiteId', width: 50, align: 'center', sortable: false,
                            formatter: function (cellvalue, options, rowObject) {
                                var html = '<input name="F_SiteId" type="checkbox" value="' + cellvalue + '|' + rowObject.F_SpaceId + '" onclick="vm.sendsite.bindChecked(this)" >';
                                return html;
                            }
                        },
                        {
                            label: 'PPT下载', name: 'F_AttachmentPpt', width: 50, align: 'center', sortable: false,
                            formatter: function (cellvalue, options, rowObject) {
                                var html = '<a href="' + cellvalue + '" title="PPT下载"  target="_blank" class="btn btn-success btn-xs"><span class="glyphicon glyphicon-download-alt"></span></a>';
                                return html;
                            }
                        },
                        {
                            label: '城市', name: 'F_CityId', width: 80, align: 'left', sortable: false,
                            formatter: function (cellvalue, options, rowObject) {
                                var length = vm.citys.length,
                                    result = '';
                                for (var i = 0; i < length; i++) {
                                    var item = vm.citys[i];
                                    if (item.Value == cellvalue) {
                                        result = item.Text;
                                        break;
                                    }
                                }
                                return result;
                            }
                        },
                        {
                            label: '区域', name: 'F_DistrictId', width: 80, align: 'left', sortable: false,
                            formatter: function (cellvalue, options, rowObject) {
                                var result = '';
                                $.ajax({
                                    url: "/OrderFlowManage/ClientOrder/GetAreasByParentIdJson?areaId=" + cellvalue,
                                    data: { areaId: cellvalue },
                                    dataType: "json",
                                    async: false,
                                    success: function (data) {
                                        result = data.F_FullName;
                                    }
                                });
                                return result;
                            }
                        },
                        {
                            label: '场地名称', name: 'F_SiteName', width: 300, align: 'left', sortable: false,
                            formatter: function (cellvalue, options, rowObject) {
                                return (cellvalue || "").replace(/\s/g, '') + "-" + rowObject.F_SpaceName;
                            }
                        },
                        {
                            label: '是否自营', name: 'F_SecondType', width: 100, align: 'center', sortable: false,
                            formatter: function (cellvalue, options, rowObject) {
                                //second_type: 自营: 10 核心: 20 联营: 30 签约: 40 普通: 50 其他: 60 黑名单: -1
                                return cellvalue == 10 ? "自营" : "其他";
                            }
                        },
                        //{
                        //    label: '地址', name: 'F_Address', width: 280, align: 'left',
                        //    formatter: function (cellvalue, options, rowObject) {
                        //        return (cellvalue || "").replace(/\s/g, '');
                        //    }
                        //},
                        { label: '场地类型', name: 'F_SiteTypeName', width: 80, align: 'left', sortable: false },
                        { label: '空间面积(㎡)', name: 'F_Area', width: 80, align: 'left', sortable: false },
                        { label: '最大容纳(人)', name: 'F_MaxPeople', width: 80, align: 'left', sortable: false },
                        { label: '市场价', name: 'F_MarketPrice', width: 80, align: 'left', sortable: false },
                        { label: 'yunspace价', name: 'F_YunPrice', width: 80, align: 'left', sortable: false },
                        {
                            label: '价格单位', name: 'F_Units', width: 80, align: 'left', sortable: false,
                            formatter: function (cellvalue, options, rowObject) {
                                if (cellvalue) {
                                    for (var i = 0; i < vm.units.length; i++) {
                                        var item = vm.units[i];
                                        if (item.Value == cellvalue) {
                                            cellvalue = item.Text;
                                            break;
                                        }
                                    }
                                }
                                return cellvalue;
                            }
                        },
                        { label: '场地编号', name: 'F_SiteId', hidden: true },
                        { label: '空间编号', name: 'F_SpaceId', hidden: true }

                    ],
                    pager: "#gridPager",
                    sortname: 'F_LastModifyTime',
                    viewrecords: true,
                    ondblClickRow: function (rowid, iRow, iCol, e) {
                        var rowobj = $gridList.getRowData(rowid);
                        vm.sendsite.bindSiteDetail(rowobj["F_SiteId"]);
                    }
                });
            }
        },
        takelook: { /*带看场地*/
            initControl: function () {
                // 回退到推荐场地
                $("#btn_takelook_prev_flow").click(function () {
                    var opts = { btn: ['是', '否'] };
                    $.modalConfirm('您是否要退回推荐场地？', function (flag) {
                        if (flag) {
                            $.submitForm({
                                url: "/OrderFlowManage/ClientOrder/BackSendSiteFlowForm?keyValue=" + orderId,
                                param: {},
                                success: function (data) { }
                            });
                        }
                    }, opts);
                });

                $("#btn_takelook").click(function () {
                    var formId = $("#F_WorkFormId").val();
                    $.modalOpen({
                        id: "ShowTakelook",
                        title: "带看预约清单",
                        url: "/OrderFlowManage/ClientOrder/ShowTakelook?orderId=" + orderId + "&formId=" + formId,
                        width: "1000px",
                        height: "300px",
                        btn: ["申请预约", "取消"],
                        callBack: function (iframeId) {
                            top.frames[iframeId].submitForm();
                        }
                    });
                });

                $("#btn_takelook_next_flow").click(function () {
                    var formId = $("#F_WorkFormId").val();
                    $.modalOpen({
                        id: "ShowTakelookFeedback",
                        title: "带看反馈",
                        url: "/OrderFlowManage/ClientOrder/ShowTakelookFeedback?orderId=" + orderId + "&formId=" + formId,
                        width: "1000px",
                        height: "300px",
                        //btn: vm.orderInfo.F_OrderState < 3 ? ["确认", "取消"] : [],
                        callBack: function (iframeId) {
                            top.frames[iframeId].submitForm();
                        }
                    });
                });

            },
            preview: function (siteId, spaceId) {
                $.modalOpen({
                    id: "ShowPreviewService",
                    title: "预约",
                    url: "/OrderFlowManage/ClientOrder/ShowPreviewService?orderId=" + orderId + "&siteId=" + siteId + "&spaceId=" + spaceId,
                    width: "800px",
                    height: "400px",
                    callBack: function (iframeId) {
                        top.frames[iframeId].submitForm();
                    }
                });
            },
            previewTime: function (siteId, spaceId) {
                $.modalOpen({
                    id: "PreviewTime",
                    title: "预约时间",
                    url: "/OrderFlowManage/ClientOrder/PreviewTime?orderId=" + orderId + "&siteId=" + siteId + "&spaceId=" + spaceId,
                    width: "400px",
                    height: "250px",
                    callBack: function (iframeId) {
                        top.frames[iframeId].submitForm();

                        vm.takelook.tabnav(1);
                    }
                });
            },
            previewCar: function (siteId, spaceId) {
                $.modalOpen({
                    id: "PreviewCar",
                    title: "预约车辆",
                    url: "/OrderFlowManage/ClientOrder/PreviewCar?orderId=" + orderId + "&siteId=" + siteId + "&spaceId=" + spaceId,
                    width: "500px",
                    height: "400px",
                    callBack: function (iframeId) {
                        top.frames[iframeId].submitForm();

                        vm.takelook.tabnav(3);
                    }
                });
            },
            previewPeople: function (siteId, spaceId) {
                $.modalOpen({
                    id: "PreviewPeople",
                    title: "预约陪同人员",
                    url: "/OrderFlowManage/ClientOrder/PreviewPeople?orderId=" + orderId + "&siteId=" + siteId + "&spaceId=" + spaceId,
                    width: "500px",
                    height: "400px",
                    callBack: function (iframeId) {
                        top.frames[iframeId].submitForm();

                        vm.takelook.tabnav(2);
                    }
                });
            },
            tabnav: function (tabType) {
                $('#takelookNavTabs li, .takelook-content').removeClass('active');
                $('#takelookNavTabs li:nth-child(' + tabType + '), #preview' + tabType).addClass('active');
            },
            initSendSite: function () {
                $.ajax({
                    url: "/OrderFlowManage/ClientOrder/GetSendSiteGridByTakelookJson",
                    data: { orderId: orderId },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        //console.log("GetSendSiteGridByTakelookJson:   "+JSON.stringify(data));
                        var html = '';
                        if (data && data.rows) {
                            for (var i = 0; i < data.rows.length; i++) {
                                var item = data.rows[i];
                                html += '<tr>';
                                //html += '   <td>';
                                //html += '       <input type="checkbox" name="takelookgroup" value="' + item.F_Id + '" />';
                                //html += '   </td>';
                                html += '   <td>';
                                html += item.F_OrderId;
                                html += '   </td>';
                                html += '   <td>';
                                html += item.F_No;
                                html += '   </td>';
                                html += '   <td>';
                                html += item.CustomerName || "";
                                html += '   </td>';
                                html += '   <td>';
                                html += item.CustomerPhone || "";
                                html += '   </td>';
                                html += '   <td>';
                                html += item.CompanyName || "";
                                html += '   </td>';
                                html += '   <td>';
                                html += item.SiteName + '-' + item.SpaceName;
                                html += '   </td>';
                                html += '   <td>';
                                html += item.LookUserName;
                                html += '   </td>';
                                html += '   <td>';
                                html += item.F_CreatorTime;
                                html += '   </td>';
                                html += '   <td>';
                                html += '       <div class="btn-group btn-group-xs">';
                                //html += '           <button type="button" class="btn btn-link" onclick="vm.takelook.previewTime(\'' + item.F_SiteId + '\', \'' + item.F_SpaceId + '\')">预约时间</button>';
                                //html += '           <button type="button" class="btn btn-link" onclick="vm.takelook.previewCar(\'' + item.F_SiteId + '\', \'' + item.F_SpaceId + '\')">预约车辆</button>';
                                //html += '           <button type="button" class="btn btn-link" onclick="vm.takelook.previewPeople(\'' + item.F_SiteId + '\', \'' + item.F_SpaceId + '\')">预约陪同人员</button>';

                                html += '           <button type="button" class="btn btn-link" onclick="vm.takelook.preview(\'' + item.F_SiteId + '\', \'' + item.F_SpaceId + '\')">预约</button>';
                                html += '       </div>';
                                html += '   </td>';
                                html += '</tr>';
                            }
                        }
                        $("#takelookGrid").html(html);
                    }
                });
            },
            initTakelook: function () {
                $.ajax({
                    url: "/OrderFlowManage/ClientOrder/GetTakelookDetailJson",
                    data: { orderId: orderId },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        //console.log(JSON.stringify(data));
                        var timeHtml = '',
                            peopleHtml = '',
                            carHtml = '',
                            timeIndex = 1,
                            peopleIndex = 1,
                            carIndex = 1;

                        if (data && data.rows) {
                            for (var i = 0; i < data.rows.length; i++) {
                                var item = data.rows[i];
                                if (item.F_SourceType == 1) {
                                    var time = JSON.parse(item.F_Source);
                                    timeHtml += '<tr>';
                                    timeHtml += '   <td>';
                                    timeHtml += timeIndex;
                                    timeHtml += '   </td>';
                                    timeHtml += '   <td>';
                                    timeHtml += item.SiteName + '-' + item.SpaceName;
                                    timeHtml += '   </td>';
                                    timeHtml += '   <td>';
                                    timeHtml += time.startTime;
                                    timeHtml += '   </td>';
                                    timeHtml += '   <td>';
                                    timeHtml += time.endTime;
                                    timeHtml += '   </td>';
                                    timeHtml += '</tr>';
                                    timeIndex++;
                                } else if (item.F_SourceType == 2) {
                                    var car = JSON.parse(item.F_Source);
                                    carHtml += '<tr>';
                                    carHtml += '   <td>';
                                    carHtml += carIndex;
                                    carHtml += '   </td>';
                                    carHtml += '   <td>';
                                    carHtml += item.SiteName + '-' + item.SpaceName;
                                    carHtml += '   </td>';
                                    carHtml += '   <td>';
                                    carHtml += car.resName;
                                    carHtml += '   </td>';
                                    carHtml += '   <td>';
                                    carHtml += car.carName;
                                    carHtml += '   </td>';
                                    carHtml += '   <td>';
                                    carHtml += car.driverName;
                                    carHtml += '   </td>';
                                    carHtml += '</tr>';
                                    carIndex++;
                                } else if (item.F_SourceType == 3) {
                                    var people = JSON.parse(item.F_Source);
                                    peopleHtml += '<tr>';
                                    peopleHtml += '   <td>';
                                    peopleHtml += peopleIndex;
                                    peopleHtml += '   </td>';
                                    peopleHtml += '   <td>';
                                    peopleHtml += item.SiteName + '-' + item.SpaceName;
                                    peopleHtml += '   </td>';
                                    peopleHtml += '   <td>';
                                    peopleHtml += people.deptName;
                                    peopleHtml += '   </td>';
                                    peopleHtml += '   <td>';
                                    peopleHtml += people.userName;
                                    peopleHtml += '   </td>';
                                    peopleHtml += '</tr>';
                                    peopleIndex++;
                                }
                            }
                        }
                        $("#previewTime").html(timeHtml || '<tr><td colspan="4" style="color: red;">没有相关数据</td></tr>');
                        $("#previewPeople").html(peopleHtml || '<tr><td colspan="4" style="color: red;">没有相关数据</td></tr>');
                        $("#previewCar").html(carHtml || '<tr><td colspan="5" style="color: red;">没有相关数据</td></tr>');

                    }
                });
            },
            init: function () {
                // 初始化带看记录 选项卡
                vm.takelook.tabnav(1);
                // 初始化 操作控件
                vm.takelook.initControl();
                // 初始化推荐场地
                vm.takelook.initSendSite();
                // 初始化带看记录
                vm.takelook.initTakelook();
            }
        },
        intentionsite: { /*意向场地确认 发送场地报价*/
            initControl: function () {
                var formId = $("#F_WorkFormId").val();
                $("#btn_intentionsite").click(function () {
                    valid_checkbox.call($("#intentionSiteGrid"), function (cks) {
                        if (cks.length == 1) {
                            $.submitForm({
                                url: "/OrderFlowManage/ClientOrder/SubmitIntentionSiteForm?keyValue=" + orderId,
                                param: {
                                    OrderId: orderId,
                                    SiteIds: cks,
                                    No: cks[0].split('|')[2],
                                    FlowFormId: formId
                                },
                                success: function (data) { }
                            });
                        } else {
                            $.modalMsg("一次最多只能申请一个批次的报价", "success");
                        }
                    });
                });

                $("#btn_intentionsite_service").click(function () {
                    $.modalOpen({
                        id: "ShowIntentionService",
                        title: "配套服务",
                        url: "/OrderFlowManage/ClientOrder/ShowIntentionService?keyValue=" + orderId,
                        width: "800px",
                        height: "400px",
                        callBack: function (iframeId) {
                            top.frames[iframeId].submitForm();
                        }
                    });
                });

            },
            del_service: function (intentionId) {
                $.modalConfirm("您确认要删除此条记录吗?", function (flag) {
                    if (flag) {
                        $.submitForm({
                            url: "/OrderFlowManage/ClientOrder/DeleteIntentionServiceForm?keyValue=" + intentionId,
                            param: {},
                            success: function () {
                                vm.intentionsite.initIntentionService();
                                $.loading(false);
                            }
                        });
                    }
                });
            },
            initIntentionService: function () {
                $.ajax({
                    url: "/OrderFlowManage/ClientOrder/GetIntentionDetailJson",
                    data: { orderId: orderId },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        //console.log('IntentionService: ' + JSON.stringify(data));
                        var html = '';
                        if (data && data.rows) {
                            for (var i = 0; i < data.rows.length; i++) {
                                var item = data.rows[i];
                                html += '<tr>';
                                html += '   <td>';
                                html += (i + 1);
                                html += '   </td>';
                                html += '   <td>';
                                html += item.SiteName + '-' + item.SpaceName;
                                html += '   </td>';
                                html += '   <td>';
                                html += item.F_ServiceName;
                                html += '   </td>';
                                html += '   <td>';
                                html += item.F_Price || '';
                                html += '   </td>';
                                html += '   <td>';
                                html += item.F_PriceUnit || '';
                                html += '   </td>';
                                html += '   <td>';
                                html += item.F_Num || '';
                                html += '   </td>';
                                html += '   <td>';
                                html += item.F_Remark || '';
                                html += '   </td>';
                                html += '   <td>';
                                html += '<button onclick="vm.intentionsite.del_service(\'' + item.F_Id + '\')" type="button" class="btn btn-link btn-xs">删除</button>';
                                html += '   </td>';
                                html += '</tr>';
                            }
                        }
                        //console.log(html);
                        //console.log($("#intentionSiteGrid").length)
                        $("#intentionServiceGrid").html(html);
                    }
                });
            },
            initIntentionSite: function () {
                $.ajax({
                    url: "/OrderFlowManage/ClientOrder/GetTakelookGridByIntentionSiteJson",
                    data: { orderId: orderId },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        //console.log('IntentionSite: '+JSON.stringify(data));
                        var html = '',
                            first = '';
                        if (data && data.rows) {
                            var activityTheme = $("#F_ActivityTheme").val(),
                                activityCityName = $("#F_ActivityCityName").val();
                            for (var i in data.rows) {
                                var item = data.rows[i];
                                html += '<tr>';
                                html += '   <td>';
                                if (first != item.F_No) {
                                    html += '       <input type="checkbox" name="intentionsite" value="' + item.F_SiteId + '|' + item.F_SpaceId + '|' + item.F_No + '" />';
                                    first = item.F_No;
                                }
                                html += '   </td>';
                                html += '   <td>';
                                html += item.F_OrderId;
                                html += '   </td>';
                                html += '   <td>';
                                html += item.F_No;
                                html += '   </td>';
                                html += '   <td>';
                                html += activityTheme;
                                html += '   </td>';
                                html += '   <td>';
                                html += activityCityName;
                                html += '   </td>';
                                html += '   <td>';
                                html += item.SiteName + '-' + item.SpaceName;
                                html += '   </td>';
                                html += '   <td>';
                                html += item.CustomerName || '';
                                html += '   </td>';
                                html += '   <td>';
                                html += item.CustomerPhone || '';
                                html += '   </td>';
                                html += '   <td>';
                                html += item.CompanyName || '';
                                html += '   </td>';
                                html += '   <td>';
                                html += $.map(JSON.parse(item.Times), function (n) { return n.startTime + '至' + n.endTime; }).join('<br >');
                                html += '   </td>';
                                html += '   <td>';
                                html += item.OrderCustomerName;
                                html += '   </td>';
                                html += '   <td>';
                                html += item.F_CreatorTime;
                                html += '   </td>';
                                html += '</tr>';
                            }
                        }
                        $("#intentionSiteGrid").html(html);
                    }
                });
            },
            init: function () {

                vm.intentionsite.initControl();

                vm.intentionsite.initIntentionService();
                vm.intentionsite.initIntentionSite();
            }
        },
        pricetalks: {   /*价格审核*/
            initControl: function () {
                var formId = $("#F_WorkFormId").val();

                //$("#btn_pricetalks_addprice").click(function () {
                //    valid_checkbox.call($("#priceTalksGrid"), function (cks) {
                //        //console.dir(cks);
                //        if (cks.length == 1) {

                //            $.submitForm({
                //                url: "/OrderFlowManage/ClientOrder/ApplyPriceTalksFlowForm?keyValue=" + orderId,
                //                param: {
                //                    OrderId: orderId,
                //                    SiteIds: cks,
                //                    FlowFormId: formId
                //                },
                //                success: function (data) {
                //                    // 更新报价单信息
                //                    vm.pricetalks.initPriceTalks();
                //                }
                //            });
                //        } else {
                //            $.modalAlert("最多只能申请一个场地报价!", "warning");
                //        }
                //    });

                //});

                $("#btn_pricetalks_sendprice").click(function () {
                    valid_checkbox.call($("#priceTalksGrid"), function (cks) {
                        //console.dir(cks);
                        if (cks.length == 1) {
                            $.submitForm({
                                url: "/OrderFlowManage/ClientOrder/SubmitPriceTalksFlowForm?keyValue=" + orderId,
                                param: {
                                    OrderId: orderId,
                                    SiteIds: cks,
                                    No: cks[0].split('|')[2],
                                    FlowFormId: formId
                                },
                                success: function (data) { }
                            });
                        } else {
                            $.modalAlert("每次只能申请一个批次的场地报价!", "warning");
                        }
                    });
                });
            },
            lookPrice: function (siteId, spaceId) {
                vm.pricetalks.editPrice(siteId, spaceId, "view");
            },
            editPrice: function (siteId, spaceId, action) {
                action = action || "mod";
                //var btn = [];
                //if (action == "add") {
                //    btn = ["生成报价单", "取消"];
                //} else if (action == "mod") {
                //    btn = ["修改报价单", "取消"]
                //}
                $.modalOpen({
                    id: "ShowPriceDetail",
                    title: "场地报价单",
                    //url: "/CheckManager/CheckInfos/OrderPriceEdit?F_OrderId=" + orderId,
                    url: "/OrderFlowManage/ClientOrder/ShowPriceDetail?keyValue=" + orderId + "&siteId=" + siteId + "&spaceId=" + spaceId,
                    width: "1000px",
                    height: "460px",
                    btn: action == "view" ? [] : ["确认", "取消"],
                    callBack: function (iframeId) {
                        top.frames[iframeId].submitForm();
                    }
                });
            },
            initPriceTalks: function () {
                $.ajax({
                    url: "/OrderFlowManage/ClientOrder/GetIntentionSiteGridByPriceTalksJson",
                    data: { orderId: orderId },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        var html = '',
                            first = '';
                        if (data && data.rows) {
                            var activityTheme = $("#F_ActivityTheme").val(),
                                activityTypeName = $("#F_ActivityTypeName").val(),
                                companyName = $("#F_ClientName").val(),
                                activityCityName = $("#F_ActivityCityName").val();
                            for (var i in data.rows) {
                                var item = data.rows[i];
                                html += '<tr>';
                                html += '   <td>';
                                if (first != item.F_No) {
                                    html += '       <input type="checkbox" name="pricetalks" value="' + item.F_SiteId + '|' + item.F_SpaceId + '|' + item.F_No + '" />';
                                    first = item.F_No;
                                }
                                html += '   </td>';
                                html += '   <td>';
                                html += item.F_OrderId;
                                html += '   </td>';
                                html += '   <td>';
                                html += item.F_No;
                                html += '   </td>';
                                html += '   <td>';
                                html += activityCityName;
                                html += '   </td>';
                                html += '   <td>';
                                html += item.SiteName + '-' + item.SpaceName;
                                html += '   </td>';
                                html += '   <td>';
                                html += activityTypeName;
                                html += '   </td>';
                                html += '   <td>';
                                html += companyName;
                                html += '   </td>';
                                html += '   <td>';
                                html += activityTheme;
                                html += '   </td>';
                                html += '   <td>';
                                html += $.map(JSON.parse(item.Times), function (n) { return n.startTime.split(' ')[0] + '至' + n.endTime.split(' ')[0]; }).join('<br >');
                                html += '   </td>';
                                //html += '   <td>';
                                //html += item.F_MarketPrice || '';
                                //html += '   </td>';
                                html += '   <td>';
                                html += JSON.parse(item.F_ServiceName).toString();
                                html += '   </td>';
                                //html += '   <td>';
                                //html += '';
                                //html += '   </td>';
                                html += '   <td>';
                                html += item.F_CreatorTime || '';
                                html += '   </td>';
                                html += '   <td>';
                                if (item.F_PriceTalksId) {
                                    html += '   <div class="btn-group btn-group-xs">';
                                    html += '       <button onclick="vm.pricetalks.lookPrice(\'' + item.F_SiteId + '\', \'' + item.F_SpaceId + '\')" type="button" class="btn btn-link">查看报价</button>';
                                    html += '       <button onclick="vm.pricetalks.editPrice(\'' + item.F_SiteId + '\', \'' + item.F_SpaceId + '\')" type="button" class="btn btn-link">编辑报价</button>';
                                    html += '   </div>';
                                } else {
                                    html += '   <div class="btn-group btn-group-xs">';
                                    html += '       <button type="button" class="btn btn-link" disabled>查看报价</button>';
                                    html += '       <button type="button" class="btn btn-link" disabled>编辑报价</button>';
                                    html += '   </div>';
                                }
                                html += '   </td>';
                                html += '</tr>';
                            }
                        }
                        $("#priceTalksGrid").html(html)
                    }
                });
            },
            init: function () {
                var $priceTalksGrid = $("#priceTalksGrid");

                vm.pricetalks.initControl();
                vm.pricetalks.initPriceTalks();
            }
        },
        reservesite: { /*场地预定*/
            initControl: function () {
                var $reserveSiteGrid = $("#reserveSiteGrid");
                var formId = $("#F_WorkFormId").val();

                $("#btn_reservesite_add").click(function () {

                    valid_checkbox.call($reserveSiteGrid, function (cks) {
                        var opts = { btn: ['是', '否'] };
                        $.modalConfirm('您确定要预定此场地吗？', function (flag) {
                            if (flag) {
                                $.submitForm({
                                    url: "/OrderFlowManage/ClientOrder/SubmitReserveSiteFlowForm?keyValue=" + orderId,
                                    param: {
                                        OrderId: orderId,
                                        SiteIds: cks,
                                        No: cks[0].split('|')[2],
                                        FlowFormId: formId
                                    },
                                    success: function (data) {
                                        vm.reservesite.initReserveSite();
                                    }
                                });
                            }
                        }, opts);
                    });

                });
            },
            initReserveSite: function () {
                $.ajax({
                    url: "/OrderFlowManage/ClientOrder/GetPriceTalksGridByReserveSiteJson",
                    data: { orderId: orderId },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        //console.log('PriceTalks: '+JSON.stringify(data));
                        var html = '',
                            first = '',
                            allStates = ['<button type="button" class="btn btn-xs btn-default" disabled>未处理</button>', '<button type="button" class="btn btn-xs btn-success" disabled>已通过</button>', '<button type="button" class="btn btn-xs btn-danger" disabled>已驳回</button>'];
                        if (data && data.rows) {
                            var activityTheme = $("#F_ActivityTheme").val(),
                                activityTypeName = $("#F_ActivityTypeName").val(),
                                companyName = $("#F_ClientName").val(),
                                activityCityName = $("#F_ActivityCityName").val();

                            for (var i in data.rows) {
                                var item = data.rows[i];
                                html += '<tr>';
                                html += '   <td>';
                                if (first != item.F_No) {
                                    html += '       <input type="checkbox" name="reserve" value="' + item.F_SiteId + '|' + item.F_SpaceId + '|' + item.F_No + '" />';
                                    first = item.F_No;
                                }
                                html += '   </td>';
                                html += '   <td>';
                                html += item.F_OrderId;
                                html += '   </td>';
                                html += '   <td>';
                                html += item.F_No;
                                html += '   </td>';
                                html += '   <td>';
                                html += activityCityName;
                                html += '   </td>';
                                html += '   <td>';
                                html += item.SiteName + '-' + item.SpaceName;
                                html += '   </td>';
                                html += '   <td>';
                                html += item.F_ReserveTime || '';
                                html += '   </td>';
                                html += '   <td>';
                                html += item.OrderCustomerName;
                                html += '   </td>';
                                //html += '   <td>';
                                //html += allStates[item.F_State || 0];
                                //html += '   </td>';
                                html += '   <td>';
                                html += item.F_CreatorTime || '';
                                html += '   </td>';
                                html += '</tr>';
                            }
                        }
                        $("#reserveSiteGrid").html(html);
                    }
                });
            },
            init: function () {
                var $reserveSiteGrid = $("#reserveSiteGrid");

                vm.reservesite.initControl();
                vm.reservesite.initReserveSite();
            }
        },
        impress: {
            initControl: function () {
                var formId = $("#F_WorkFormId").val();
                $("#btn_impress_add").click(function () {
                    $.ajax({
                        url: "/OrderFlowManage/ClientOrder/CheckFileForm?orderId=" + orderId,
                        dataType: "json",
                        async: false,
                        success: function (data) {
                            if (data.state == "success") {
                                $.modalOpen({
                                    id: "ShowImpress",
                                    title: "用印申请",
                                    url: "/OrderFlowManage/ClientOrder/ShowImpress?keyValue=" + orderId + "&formId=" + formId,
                                    width: "1200px",
                                    height: "600px",
                                    callBack: function (iframeId) {
                                        top.frames[iframeId].submitForm();
                                    }
                                });
                            } else {
                                $.modalAlert(data.message, data.state);
                            }
                        }
                    });


                });
            },
            initImpress: function () {
                $.ajax({
                    url: "/OrderFlowManage/ClientOrder/GetImpressGridByReserveSiteJson",
                    data: { orderId: orderId },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        //console.log('GetImpressGridByReserveSiteJson: '+JSON.stringify(data));
                        var html = '',
                            first = '';
                        if (data && data.rows) {
                            var state = ["<button type='button' class='btn btn-xs btn-danger' disabled>驳回</button>", "<button type='button' class='btn btn-xs btn-success' disabled>通过</button>"],
                                activityCityName = $("#F_ActivityCityName").val();
                            for (var i in data.rows) {
                                var item = data.rows[i];

                                html += '<tr>';
                                html += '   <td>';
                                html += item.F_OrderId;
                                html += '   </td>';
                                html += '   <td>';
                                html += item.F_No;
                                html += '   </td>';

                                html += '   <td>';
                                html += activityCityName;
                                html += '   </td>';
                                html += '   <td>';
                                html += item.F_SiteName + '-' + item.F_SpaceName;
                                html += '   </td>';
                                html += '   <td>';
                                if (first != item.F_No) {
                                    html += item.F_ClientFileName ? '<a href="' + item.F_ClientFilePath + '" taget="_blank">' + item.F_ClientFileName + '</a>' : '';
                                    html += '<button type="button" class="btn btn-link btn-xs" onclick="vm.impress.uploadClientFiles(\'' + item.F_SiteId + '|' + item.F_SpaceId + '\', \'' + item.F_No + '\')">上传电子合同</button>';
                                }
                                html += '   </td>';
                                html += '   <td>';
                                if (first != item.F_No) {
                                    html += item.F_SiteFileName ? '<a href="' + item.F_SiteFilePath + '" taget="_blank">' + item.F_SiteFileName + '</a>' : '';
                                    html += '<button type="button" class="btn btn-link btn-xs" onclick="vm.impress.uploadSiteFiles(\'' + item.F_SiteId + '|' + item.F_SpaceId + '\', \'' + item.F_No + '\')">上传电子合同</button>';
                                }
                                html += '   </td>';

                                html += '   <td>';
                                html += (state[item.F_State] || "<button type='button' class='btn btn-xs btn-default' disabled>未处理</button>");
                                html += '   </td>';
                                html += '   <td>';
                                html += item.F_CreatorTime || '';
                                html += '   </td>';
                                html += '</tr>';
                                first = item.F_No;
                            }
                        }
                        //$("#btn_impress_add").prop("disabled", index > 0);
                        $("#impressGrid").html(html);
                    }
                });
            },
            uploadClientFiles: function (siteAndSpaceId, No) {
                $.modalOpen({
                    id: "Uploader",
                    title: "上传合同",
                    url: "/OrderFlowManage/ClientOrder/ShowClientUploader?orderId=" + orderId + "&siteAndSpaceId=" + siteAndSpaceId + "&No=" + No + "&StateType=1",
                    width: "800px",
                    height: "400px",
                    callBack: function (iframeId) {
                        top.frames[iframeId].submitForm();
                    }
                });
            },
            uploadSiteFiles: function (siteAndSpaceId, No) {
                $.modalOpen({
                    id: "Uploader",
                    title: "上传合同",
                    url: "/OrderFlowManage/ClientOrder/ShowSiteUploader?orderId=" + orderId + "&siteAndSpaceId=" + siteAndSpaceId + "&No=" + No + "&StateType=1",
                    width: "800px",
                    height: "400px",
                    callBack: function (iframeId) {
                        top.frames[iframeId].submitForm();
                    }
                });
            },
            init: function () {
                vm.impress.initControl();
                vm.impress.initImpress();
            }
        },
        signcontract: {  /*签订合同*/
            initControl: function () {
                var $signContract = $("#signContractGrid");
                var formId = $("#F_WorkFormId").val();

                $("#btn_signcontract_add").click(function () {

                    valid_checkbox.call($signContract, function (cks) {
                        var opts = { btn: ['是', '否'] };
                        $.modalConfirm('您确定要将此订单转为合同单吗？', function (flag) {
                            if (flag) {
                                $.submitForm({
                                    url: "/OrderFlowManage/ClientOrder/SubmitSignContractFlowForm?keyValue=" + orderId,
                                    param: {
                                        OrderId: orderId,
                                        SiteIds: cks,
                                        No: cks[0].split('|')[2],
                                        FlowFormId: formId
                                    },
                                    success: function (data) {
                                        vm.signcontract.initSignContract();
                                    }
                                });
                            }
                        }, opts);
                    });

                });
            },
            initSignContract: function () {
                $.ajax({
                    url: "/OrderFlowManage/ClientOrder/GetReserveSiteGridBySignContractJson",
                    data: { orderId: orderId },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        var html = '',
                            first = '';

                        if (data && data.rows) {
                            var activityTheme = $("#F_ActivityTheme").val(),
                                activityTypeName = $("#F_ActivityTypeName").val(),
                                companyName = $("#F_ClientName").val(),
                                activityCityName = $("#F_ActivityCityName").val();

                            for (var i in data.rows) {
                                var item = data.rows[i];
                                html += '<tr>';
                                html += '   <td>';
                                if (first != item.F_No) {
                                    html += '       <input type="checkbox" name="intentionsite" value="' + item.F_SiteId + '|' + item.F_SpaceId + '|' + item.F_No + '" />';
                                }
                                html += '   </td>';
                                html += '   <td>';
                                html += item.F_OrderId;
                                html += '   </td>';
                                html += '   <td>';
                                html += item.F_No;
                                html += '   </td>';
                                html += '   <td>';
                                html += activityCityName;
                                html += '   </td>';
                                html += '   <td>';
                                html += item.SiteName + '-' + item.SpaceName;
                                html += '   </td>';
                                html += '   <td>';
                                html += item.F_ReserveTime || '';
                                html += '   </td>';
                                html += '   <td>';
                                html += item.OrderCustomerName;
                                html += '   </td>';
                                html += '   <td>';
                                if (first != item.F_No) {
                                    html += item.F_FileName ? '<a href="' + item.F_FilePath + '" taget="_blank">' + item.F_FileName + '</a>' : '';
                                    html += '<button type="button" class="btn btn-link btn-xs" onclick="vm.signcontract.uploadFiles(\'' + item.F_SiteId + '|' + item.F_SpaceId + '\', \'' + item.F_No + '\')">上传合同</button>';
                                    first = item.F_No;
                                }
                                html += '   </td>';
                                html += '   <td>';
                                html += item.F_CreatorTime || '';
                                html += '   </td>';
                                html += '</tr>';
                            }
                        }
                        $("#signContractGrid").html(html);
                    }
                });
            },
            uploadFiles: function (siteAndSpaceId, No) {
                $.modalOpen({
                    id: "Uploader",
                    title: "上传合同",
                    url: "/OrderFlowManage/ClientOrder/Uploader?orderId=" + orderId + "&siteAndSpaceId=" + siteAndSpaceId + "&No=" + No + "&StateType=2",
                    width: "800px",
                    height: "400px",
                    callBack: function (iframeId) {
                        top.frames[iframeId].submitForm();
                    }
                });
            },
            init: function () {
                var $signContract = $("#signContractGrid");

                vm.signcontract.initControl();
                vm.signcontract.initSignContract();
            }
        },
        tabnav: function () {
            var tabType = parseInt($.request('type'));
            // 当数据类型大于此数据时，为重复了相关数据
            //if (tabType >= 5) tabType--;
            $("#stateNavTabs li:gt(" + tabType + ")").addClass("disabled").find("a").attr("href", "javascript:void(0);");
            $('#stateNavTabs li, .state-content').removeClass('active');
            $('#stateNavTabs li:nth-child(' + (tabType + 1) + '), #state' + tabType).addClass('active');

            var href = $(this).prop("href"),
                state = href ? parseInt(href.split('#state')[1]) : tabType,
                func = ["flow", "sendsite", "takelook", "intentionsite", "pricetalks", "reservesite", "impress", "signcontract",];

            if (state != func.length)
                vm[func[state]].init();
        },
        init: function () {
            vm.order.init();
            vm.tabnav();

            $('#btnCloseOrder').on('click', vm.order.close);
            $('#btnOpenReport').on('click', vm.order.report);
            $('#btnWriteReport').on('click',vm.order.write);
            $('#stateNavTabs a').on('click', vm.tabnav);
        }
    };

    $(vm.init);
</script>